import { Content, defineConfig } from "vitepress";
import { createFunction, createWithTextFunction, useFunction } from "./utils";
import linuxConfig from "./linux";
import zookeeperConfig from "./zookeeper";
import mysqlConfig from "./mysql";

const shopWithText = createWithTextFunction("/open-source/shop/");
const springWithText = createWithTextFunction("/spring/");
const boosterWithText = createWithTextFunction("/open-source/booster/");
const mysqlWithText = createWithTextFunction("/storage/mysql/");
const shop = createFunction("/open-source/shop/");
const basicWithText = createWithTextFunction("/basic/");
const mysql = createFunction("/storage/mysql/");
const docker = createFunction("/service/container/docker/");
const spring = createFunction("/spring/");

const [git, gitWithText] = useFunction("/project-management/git/");
const [mybatis, mybatisWithText] = useFunction("/storage/mybatis/");
const [redis, redisWithText] = useFunction("/storage/redis/");
const [android, androidWithText] = useFunction("/android/");
const [linux, linuxWithText] = useFunction("/service/system/linux/");
const [maven, mavenWithText] = useFunction(
  "/project-management/builder/maven/"
);
const [gradle, gradleWithText] = useFunction(
  "/project-management/builder/gradle/"
);
const [jenkins, jenkinsWithText] = useFunction("/project-management/jenkins/");

// https://vitepress.dev/reference/site-config
export default defineConfig({
  title: "Java Study World",
  description: "Java Study World",
  base: "/study-java/",
  vite: {
    resolve: {
      alias: {
        "@image": "assets/image/",
      },
    },
  },
  markdown: {
    lineNumbers: true,
    // config: (md) => {
    //   const fence = md.renderer.rules.fence!;
    //   md.renderer.rules.fence = (...args) => {
    //     const [tokens, idx] = args;
    //     console.log(tokens);
    //     return fence(...args);
    //   };
    //   md.block.ruler.before("fence", "ss", () => {
    //     return false;
    //   });
    // },
  },
  themeConfig: {
    // https://vitepress.dev/reference/default-theme-config
    nav: [
      { text: "更新日志", link: "/log" },
      {
        text: "项目管理",
        items: [
          {
            text: "构建工具",
            items: [
              { text: "Maven", link: maven() },
              { text: "Gradle", link: gradle() },
            ],
          },
          {
            text: "代码管理",
            items: [
              { text: "Jenkins", link: jenkins() },
              { text: "Git", link: git() },
            ],
          },
        ],
      },

      {
        text: "开发框架",
        items: [
          {
            text: "应用程序",
            items: [
              { text: "Spring", link: "/spring/" },
              { text: "Android", link: android() },
            ],
          },
          {
            text: "数据存储",
            items: [{ text: "MyBatis", link: mybatis() }],
          },
        ],
      },
      {
        text: "数据存储",
        items: [
          { text: "MySQL", link: mysql() },
          { text: "Redis", link: redis() },
        ],
      },
      {
        text: "服务管理",
        items: [
          {
            text: "操作系统",
            items: [{ text: "Linux", link: linux() }],
          },
          {
            text: "容器管理",
            items: [{ text: "Docker", link: docker() }],
          },
        ],
      },
      {
        text: "高级应用",
        items: [
          {
            text: "常用类库",
            link: "/library/",
          },
          {
            text: "架构设计",
            items: [{ text: "微服务", link: "/micro-service" }],
          },
          {
            text: "软件服务",
            items: [
              { text: "Duboo", link: "/duboo/" },
              { text: "Zookeeper", link: "/zookeeper/" },
            ],
          },
          {
            text: "消息队列",
            items: [
              {
                text: "RabbitMQ",
                link: "/message-queue/rabbit-mq/",
              },
            ],
          },
          { text: "单元测试", link: "/unit-tests/" },
        ],
      },
      {
        text: "开源项目",
        items: [
          { text: "低代码平台", link: "/open-source/booster/" },
          { text: "电商项目", link: shop() },
        ],
      },
    ],

    sidebar: {
      [jenkins()]: [
        {
          text: "Jenkins 基础",
          items: [jenkinsWithText()],
        },
      ],
      [gradle()]: [
        {
          text: "Gradle 基础",
          items: [gradleWithText()],
        },
      ],
      [android()]: [
        {
          text: "Android 基础",
          items: [androidWithText()],
        },
      ],
      [shop()]: [
        {
          text: "前台项目",
          items: [
            shopWithText("frontend/index"),
            shopWithText("frontend/layout"),
            shopWithText("frontend/home"),
          ],
        },
        {
          text: "后台项目",
          items: [
            shopWithText(),
            shopWithText("dashboard"),
            {
              text: "会员列表",
              items: [shopWithText("member-level"), shopWithText("user")],
            },
            shopWithText("order"),
            shopWithText("permission"),
            {
              text: "商品管理",
              items: [
                shopWithText("product-category"),
                shopWithText("product"),
              ],
            },
          ],
        },
      ],
      [docker()]: [
        {
          text: "基础",
          items: [{ text: "核心概念", link: docker() }],
        },
      ],
      [linux()]: linuxConfig,
      "/message-queue/rabbit-mq/": [
        { text: "基本介绍", link: "/message-queue/rabbit-mq/" },
        { text: "软件安装", link: "/message-queue/rabbit-mq/install" },
      ],
      "/duboo/": [{ text: "基本介绍", link: "/duboo/" }],
      "/zookeeper/": zookeeperConfig,
      "/open-source/booster/": [
        boosterWithText(),
        boosterWithText("string-utils"),
        boosterWithText("schema"),
        boosterWithText("file-system"),
        boosterWithText("commander"),
      ],
      [redis()]: [
        {
          text: "Redis 基础",
          items: [
            redisWithText(),
            redisWithText("install"),
            redisWithText("common-operations"),
            redisWithText("strings"),
            redisWithText("lists"),
            redisWithText("sets"),
            redisWithText("hashes"),
            redisWithText("sorted-sets"),
            redisWithText("expiration"),
          ],
        },
        {
          text: "Redis 进阶",
          items: [],
        },
      ],
      "/unit-tests/": [
        { text: "简介", link: "/unit-tests/" },
        { text: "断言", link: "/unit-tests/assertion" },
      ],
      [git()]: [
        {
          text: "Git 基础",
          items: [
            gitWithText(),
            gitWithText("install"),
            gitWithText("repository-local"),
            gitWithText("repository-remote"),
            gitWithText("branch"),
          ],
        },
        {
          text: "Git 进阶",
          items: [
            gitWithText("submodule"),
            gitWithText("server"),
            gitWithText("hook"),
            gitWithText("checkout"),
          ],
        },
      ],
      "/open-source/": [{ text: "低代码平台", link: "/booster/" }],
      "/library/": [
        {
          text: "基础",
          items: [
            { text: "类库概述", link: "./" },
            { text: "java.util.Properties", link: "./properties" },
            { text: "javax.sql.DataSource", link: "./data-source" },
          ],
        },
      ],
      "/storage/mybatis/": [
        {
          text: "MyBatis 基础",
          items: [
            { text: "核心概念", link: mybatis() },
            { text: "快速入门", link: mybatis("getting-started") },
            { text: "数据源", link: mybatis("data-source") },
            { text: "应用配置", link: mybatis("config") },
            { text: "映射配置", link: mybatis("mapper") },
            { text: "动态语句", link: mybatis("dynamic-sql") },
          ],
        },
        {
          text: "MyBatis 进阶",
          items: [{ text: "复杂映射", link: mybatis("mapper-complex") }],
        },
      ],
      "/storage/mysql/": mysqlConfig,
      [maven()]: [
        {
          text: "Maven 基础",
          items: [
            mavenWithText(),
            mavenWithText("install"),
            { text: "快速入门", link: "/maven/getting-started" },
            { text: "目录结构", link: "/maven/directory-structure" },
            { text: "常用命令", link: "/maven/command" },
            { text: "资源目录", link: "/maven/resource-directory" },
            { text: "插件管理", link: "/maven/plugins" },
            { text: "依赖管理", link: "/maven/dependency" },
            mavenWithText("repository"),
          ],
        },
        {
          text: "Maven 进阶",
          items: [],
        },
      ],
      [spring()]: [
        {
          text: "Spring Basic",
          items: [
            springWithText(),
            springWithText("getting-started"),
            springWithText("generate"),
            springWithText("controller"),
            springWithText("web-server"),
            springWithText("ioc"),
            springWithText("di"),
            springWithText("database"),
            springWithText("resource-static"),
            springWithText("uploading-files"),
            // { text: "注解", link: "/spring/annotation" },
            // { text: "数据库操作", link: "/spring/database-handle" },
          ],
        },
        {
          text: "Spring Boot",
          items: [springWithText("spring-boot")],
        },
        {
          text: "Spring Framework",
          items: [springWithText("mvc")],
        },
      ],
      "/": [
        {
          text: "JAVA 基础",
          items: [
            basicWithText(),
            basicWithText("install"),
            { text: "快速入门", link: "/basic/getting-started" },
            { text: "变量", link: "/basic/variable" },
            { text: "类和对象", link: "/basic/classes-object" },
            { text: "判断流程", link: "/basic/condition" },
            { text: "循环", link: "/basic/loop" },
            { text: "运算符", link: "/basic/operator" },
            { text: "日期", link: "/basic/date" },
            { text: "正则表达式", link: "/basic/regexp" },
            { text: "字符串", link: "/basic/string" },
            { text: "数组", link: "/basic/array" },
            { text: "整数", link: "/basic/integer" },
            { text: "继承", link: "/basic/extends" },
            { text: "接口", link: "/basic/interface" },
            { text: "多态", link: "/basic/polymorphic" },
            { text: "文件系统", link: "/basic/filesystem" },
            { text: "异常处理", link: "/basic/exception" },
            { text: "命令行终端", link: "/basic/command" },
            { text: "路径", link: "/basic/path" },
          ],
        },
        {
          text: "进阶",
          items: [
            { text: "泛型", link: "/advance/genericity" },
            { text: "数组列表", link: "/advance/array-list" },
            { text: "散列表", link: "/advance/hash-map" },
            { text: "多线程", link: "/advance/multi-thread" },
            { text: "网络编程", link: "/advance/network" },
            { text: "数据库操作", link: "/advance/database-handle" },
            { text: "类和对象", link: "/advance/classes" },
            { text: "数据格式", link: "/advance/data-format" },
            { text: "流操作", link: "/advance/stream" },
            { text: "动态字符串", link: "/advance/string-builder" },
            { text: "字符串", link: "/advance/string" },
          ],
        },
      ],
    },

    socialLinks: [
      { icon: "github", link: "https://github.com/vuejs/vitepress" },
    ],
  },
});
